﻿Imports System
Imports System.Runtime.Serialization
Imports System.Security.Permissions

Namespace System.Workflow.ComponentModel.Compiler
    <Serializable> _
    Public NotInheritable Class WorkflowValidationFailedException
        Inherits Exception
        ' Methods
        Public Sub New()
            MyBase.New(SR.GetString("Error_WorkflowLoadValidationFailed"))
        End Sub

        Public Sub New(ByVal message As String)
            MyBase.New(message)
        End Sub

        Private Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            MyBase.New(info, context)
            If (info Is Nothing) Then
                Throw New ArgumentNullException("info")
            End If
            Me.errors = DirectCast(info.GetValue("errors", GetType(ValidationErrorCollection)), ValidationErrorCollection)
            If (Me.errors Is Nothing) Then
                Throw New SerializationException(SR.GetString("Error_SerializationInsufficientState"))
            End If
        End Sub

        Public Sub New(ByVal message As String, ByVal innerException As Exception)
            MyBase.New(message, innerException)
        End Sub

        Public Sub New(ByVal message As String, ByVal errors As ValidationErrorCollection)
            MyBase.New(message)
            If (errors Is Nothing) Then
                Throw New ArgumentNullException("errors")
            End If
            Me.errors = XomlCompilerHelper.MorphIntoFriendlyValidationErrors(errors)
        End Sub

        <SecurityPermission(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.SerializationFormatter)> _
        Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            If (info Is Nothing) Then
                Throw New ArgumentNullException("info")
            End If
            MyBase.GetObjectData(info, context)
            info.AddValue("errors", Me.errors, GetType(ValidationErrorCollection))
        End Sub


        ' Properties
        Public ReadOnly Property Errors As ValidationErrorCollection
            Get
                Return Me.errors
            End Get
        End Property


        ' Fields
        Private errors As ValidationErrorCollection
    End Class
End Namespace

